﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using mfXmlSerializer.TestObjects;
using System.IO;
using System.Threading;
using System.Globalization;

namespace mfXmlSerializer.Test
{
    [TestClass]
    public class CombinedTests
    {
        [TestMethod]
        public void Serialize_Deserialize_Valid_SimpleParameterObject()
        {
            TestSetUps.SetupDateTimeTests();

            //get object 2 serialize
            var para = TestDataFactory.CreateSimpleCompleteParameter();

            var serPara = new mfXmlTypedSerializer(para.GetType());
            String curXml = serPara.Serialize(para);

            String refXml = TestDataFactory.CreateSimpleCompleteParameterString();

            Console.WriteLine("ref xml: \t" + refXml);
            Console.WriteLine("cur xml: \t" + curXml);

            Assert.AreEqual(refXml, curXml);

            //deserialie serialized object
            var paraDeserialized = serPara.Deserialize(curXml) as Parameter;

            DeserializeTests.CheckDeserializedSimpleParameterObject(paraDeserialized, created: new DateTime(2014, 1, 12, 13, 12, 00));
        }

        [TestMethod]
        public void Serialize_Deserialize_Valid_SimpleParameterObject_WithMissingVersionElement()
        {
            TestSetUps.SetupDateTimeTests();

            //get object 2 serialize
            var para = TestDataFactory.CreateParameter_WithVersionNULL();

            var serPara = new mfXmlTypedSerializer(para.GetType());
            String curXml = serPara.Serialize(para);

            String refXml = TestDataFactory.CreateParameterString_WithMissingVersionElement();

            Console.WriteLine("ref xml: \t" + refXml);
            Console.WriteLine("cur xml: \t" + curXml);

            Assert.AreEqual(refXml, curXml);

            //deserialie serialized object
            var paraDeserialized = serPara.Deserialize(curXml) as Parameter;

            Assert.AreEqual(para.Version, paraDeserialized.Version);

            DeserializeTests.CheckDeserializedSimpleParameterObject(paraDeserialized
                , created: new DateTime(2014, 1, 12, 13, 12, 00)
                , version: null);
        }

        [TestMethod]
        public void Serialize_Deserialize_Valid_SimpleParameterObject_WithMissingLoggingElement()
        {
            TestSetUps.SetupDateTimeTests();

            //get object 2 serialize
            var para = TestDataFactory.CreateParameter_WithLoggingNULL();

            var serPara = new mfXmlTypedSerializer(para.GetType());
            String curXml = serPara.Serialize(para);

            String refXml = TestDataFactory.CreateParameterString_WithMissingLoggingElement();

            Console.WriteLine("ref xml: \t" + refXml);
            Console.WriteLine("cur xml: \t" + curXml);

            Assert.AreEqual(refXml, curXml);

            //deserialie serialized object
            var paraDeserialized = serPara.Deserialize(curXml) as Parameter;

            DeserializeTests.CheckDeserializedSimpleParameterObject(paraDeserialized
                , created: new DateTime(2014, 1, 12, 13, 12, 00)
                , traceLevel: new Logging().TraceLevel
                , loggingActive: new Logging().FileLoggingActive);
        }

        [TestMethod]
        public void Serialize_Deserialize_Valid_CultureContainer_enUS()
        {
            var culCon = new CultureContainer();

            var serCulCon = new mfXmlTypedSerializer(culCon.GetType());
            var curXml = serCulCon.Serialize(culCon);

            Console.WriteLine("cur xml: \t" + curXml);

            var desCulCon = serCulCon.Deserialize(curXml) as CultureContainer;

            Assert.AreEqual(culCon.Culture.ToString(), desCulCon.Culture.ToString());
        }

        [TestMethod]
        public void Serialize_Deserialize_Valid_RSSSample_Complete()
        {
            TestSetUps.SetupDateTimeTests();

            //get object 2 serialize
            var rss = TestDataFactory.CreateRSSSample_Complete();

            var serRSS = new mfXmlTypedSerializer(rss.GetType());
            String curXml = serRSS.Serialize(rss);

            String refXml = TestDataFactory.CreateRSSSampleString_Complete_Deserialized_WithoutRSSVersionAttribute();

            Console.WriteLine("ref xml: \t" + refXml);
            Console.WriteLine("cur xml: \t" + curXml);

            Assert.AreEqual(refXml, curXml);

            //deserialie serialized object
            var rssDeserialized = serRSS.Deserialize(curXml) as rss;

            DeserializeTests.CheckRSSSample_Complete(rssDeserialized);
        }
    }
}
